package com.qcby.system.api.factory;

import com.baomidou.mybatisplus.extension.api.R;
import com.qcby.common.core.domain.Result;
import com.qcby.system.api.domain.param.SysLoginInfoRequest;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.qcby.system.api.RemoteLogService;
import com.qcby.system.api.domain.SysLogininfor;
import com.qcby.system.api.domain.SysOperLog;

/**
 * 日志服务降级处理
 * 
 * @author qcby
 */
@Component
@Slf4j
public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogService>
{

    @Override
    public RemoteLogService create(Throwable throwable)
    {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new RemoteLogService()
        {
            @Override
            public Result<Boolean> saveLog(SysOperLog sysOperLog, String source)
            {
                return Result.getServiceError("保存操作日志失败:" + throwable.getMessage());
            }

            @Override
            public Result<Boolean> saveLoginInfo(SysLoginInfoRequest sysLoginInfoRequest, String source)
            {
                return Result.getServiceError("保存登录日志失败:" + throwable.getMessage());
            }
        };

    }
}
